/**
 * 公共模块JS调用
 * author: zhanghua 2015-9-9
 */
$(function(){
	global();
	quit();
})
var post_json = function(posturl,postdata,successhandle,errorhandle,sync){
    $.ajax({
        url: posturl,
        type: 'POST',
        dataType: 'json',
        cache: false,
        data: postdata,
        async:!sync,
        success: function (data) {
            successhandle(data);
        },
        error: function () {
            if (errorhandle)
                errorhandle('服务器超时，请重试!');
            else{
            	console.log('服务器返回数据格式出现异常');
            }
        }
    });
};

var quit = function(){
	$(".quit").click(function(){
        if(confirm("你确定要退出登录吗？")){
        	location.href = $(this).attr('data');
        }
    });
};

var global = function(){
	App.init();
	//$('.select2-search').remove();
    $('label.tree-list').click(function () {
        var icon = $(this).children(".fa");
        if (icon.hasClass("fa-folder-o")) {
            icon.removeClass("fa-folder-o").addClass("fa-folder-open-o");
        } else {
            icon.removeClass("fa-folder-open-o").addClass("fa-folder-o");
        }

        $(this).parent().children('ul.tree').toggle(300, function () {
            $(this).parent().toggleClass("open");
            $(".tree .nscroller").nanoScroller({
                preventPageScrolling: true
            });
        });
    });
    
    $('.searchoption').click(function () {
        $(this).closest('.col-sm-12').hide();
        $('.search-plan').toggle();
    });
    
    $('.content tr').hover(function () {
        $(this).addClass("table-hover");
    }, function () {
        $(this).removeClass("table-hover");
    });
    
    $('.image-zoom').magnificPopup({
		type : 'image',
		mainClass : 'mfp-with-zoom', // this class is for CSS animation below
		zoom : {
			enabled : true, // By default it's false, so don't forget to enable it
			duration : 300, // duration of the effect, in milliseconds
			easing : 'ease-in-out', // CSS transition easing function
			opener : function(openerElement) {
				var parent = $(openerElement);
				return parent;
			}
		}
	});
    
    $('#stime').datetimepicker({
    	format : 'yyyy-mm-dd',
    	showMeridian : true,
    	autoclose : true,
    	pickDate : true,
    	minView : 2,
    	pickTime : true,
    	todayBtn : true
    }).on('changeDate',function(ev){
    	var stime = $('#stime').val();
    	$('#etime').datetimepicker('setStartDate',stime);
    	$('#stime').datetimepicker('hide');
    });
    
    $('#etime').datetimepicker({
    	format : 'yyyy-mm-dd',
    	showMeridian : true,
    	autoclose : true,
    	pickDate : true,
    	minView : 2,
    	pickTime : true,
    	todayBtn : true
    }).on('changeDate',function(ev){
    	var etime = $('#etime').val();
    	$('#stime').datetimepicker('setEndDate',etime);
    	$('#etime').datetimepicker('hide');
    });
    
    $('#mstime').datetimepicker({
    	format : 'yyyy-mm-dd',
    	showMeridian : true,
    	autoclose : true,
    	pickDate : true,
    	minView : 2,
    	pickTime : true,
    	todayBtn : true
    }).on('changeDate',function(ev){
    	var stime = $('#mstime').val();
    	$('#metime').datetimepicker('setStartDate',stime);
    	$('#mstime').datetimepicker('hide');
    });
    
    $('#metime').datetimepicker({
    	format : 'yyyy-mm-dd',
    	showMeridian : true,
    	autoclose : true,
    	pickDate : true,
    	minView : 2,
    	pickTime : true,
    	todayBtn : true
    }).on('changeDate',function(ev){
    	var etime = $('#metime').val();
    	$('#mstime').datetimepicker('setEndDate',etime);
    	$('#metime').datetimepicker('hide');
    });
}
